package com.ybfenpan.servlet;


import com.ybfenpan.tracer.Debug;
import com.ybfenpan.utils.ContextUtil;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

public class ClassLoadServlet extends HttpServlet {

	public ClassLoadServlet() {

    }
	
	/**
     * @param theConfig theConfig
     * @throws ServletException ServletException
     */
    public void init(ServletConfig theConfig) throws ServletException {
    	super.init(theConfig);
        try {
            String webApp = theConfig.getServletContext().getServletContextName();
            // 注入ServletContext
            try {
            	ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(theConfig.getServletContext());
            	ContextUtil.setContext(ctx);
                Debug.info("Initiating WebApplicationContext OK!");
            } catch (Exception e) {
                Debug.info("$$can not get WebApplicationContext!$$");
            }

            // other Initiating



        } catch (Exception e) {
            Debug.printErr(e);
        }
    }
    
    
    
}
